package com.huyucheng.todolist

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.widget.Toast

class MyDatabaseHelper(val context: Context?, name: String, version: Int) :
    SQLiteOpenHelper(context, name, null, version) {

    private val createTodo = "" +
            "create table Todo\n" +
            "(\n" +
            "    id       INTEGER      not null\n" +
            "        constraint Todo_pk\n" +
            "            primary key autoincrement,\n" +
            "    content  varchar(100) not null,\n" +
            "    checked  tinyint default 0 not null,\n" +
            "    priority int     default 0 not null\n" +
            ");\n" +
            "\n" +
            "create unique index Todo_id_uindex\n" +
            "    on Todo (id);\n"

    override fun onCreate(db: SQLiteDatabase?) {
        db?.execSQL(createTodo)
        Toast.makeText(context, "Create Succeeded", Toast.LENGTH_SHORT).show()
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
    }

}